#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
struct NODE
{
	char c;
	int x;
	bool operator<(const NODE &B) const { return x < B.x; }
} ans[N];
int a[30], len;
string s;

int main()
{
	cin >> s;
	for (int i = 0; i < 26; i++)
		a[s[i] - 'a'] = i;
	cin >> s;
	len = s.length();
	for (int i = 0; i < len; i++)
	{
		ans[i].c = s[i], ans[i].x = a[s[i] - 'a'];
	}
	sort(ans, ans + len);
	for (int i = 0; i < len; i++)
		cout << ans[i].c;
	return 0;
}